<template>
  <div class='discount first-box'>
    <Search :searchFun="getSearch"></Search>
    <LineGray></LineGray>

    <Scroll :hasmore="hasmore" :pullup="pullup" setHeight="-60">
      <List :data="discountListData"></List>
    </Scroll>
  </div>
</template>
<script>
import Search from '../../common/search'
import LineGray from '../../common/line.vue'
import Scroll from '../../common/scroller'
import List from "./common/list"
export default {
  components: {Search,LineGray,Scroll,List},
  name: "",
  data() {
    return {
      hasmore:false,

      discountListData:[
        // {
        //   id:1,
        //   img:require('../../../assets/img/hpmepage/sense/1.png'),
        //   people:50,
        //   time:36001,
        //   over:false
        // },
      ],
      searchContent:"",//搜素内容
      timeSet:null,//定时器
      pageInfo:{
        page:1
      },
      hasmore:false,
    };
  },
  methods: {
    getSearch(search){
      this.searchContent=search
      this.getList()
    },

    // 下拉刷新方法回调
    pullup(func){
      if(this.hasmore){
        this.pageInfo.page++
         _g.orderList([this.getList,func])
         return
      }
    },
    getList(){
      var params={
        currPageNo:this.pageInfo.page,
        activityTitle:this.searchContent
      }
      _g.apiPost("activity/getActivities.do",params).then(res=>{
        if(res.status==1){
          _g.toMessage(res)
          return
        }
        this.hasmore=res.data.hasNextPage
        var goal=[]
        res.data.list.forEach(ele => {
          goal.push({
            id:ele.id,
            img:ele.picture||"https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2062407685,4236406183&fm=27&gp=0.jpg",
            people:ele.enrollNum||0,
            time:(new Date(ele.endTimes).getTime()-new Date().getTime())/1000,//秒
            over:(new Date(ele.endTimes).getTime()-new Date().getTime())>0?false:true
          })
        });
        this.$set(this,"discountListData",this.discountListData.concat(goal))
      }).then(()=>{
        if(this.timeSet)clearInterval(this.timeSet)
        this.timeSet=setInterval(()=>{
          this.discountListData.forEach(ele=>{
            if(!ele.over){
              ele.time--
            }
            if(ele.time<0){
              ele.over=true
            }
          })
        },1000)
      })
    }
  },
  created() {
    this.getList()
  },
  beforeDestroy() {
    if(this.timeSet)clearInterval(this.timeSet)
  },
};
</script>
<style lang="scss" scoped>
.discount {

}
</style>